package cn.tedu._08security.base.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                //1.配置请求授权规则
                .authorizeRequests()
                .antMatchers("/api/public/**").permitAll()//不需要认证的,直接访问资源
                .anyRequest().authenticated()//其他的都需要认证
                .and()
                .csrf().disable()
                //2.配置表单登录
                .formLogin()
                .defaultSuccessUrl("/index.html")
                .permitAll()//
                .and()
                //3.配置登出
                .logout()
                .permitAll();
    }
}
